﻿// Screenshotz
//
// Copyright © Frank Nagl, 2008-2012
// admin@franknagl.de
// www.franknagl.de
//
namespace Screenshotz
{
    using System;
    using System.Windows.Forms;
    using Nail;
    using SBIP;

    partial class ImageCutForm
    {
        private void ItemClipboardClick(object sender, EventArgs e)
        {
            MessageBox.Show(language.Text[13], language.Text[14], MessageBoxButtons.OK);
        }

        private void ItemCloseClick(object sender, EventArgs e)
        {
            Close();
        }

        private void ItemfinishClick(object sender, EventArgs e)
        {
            IsExit = true;
            Close();

            //if (MessageBox.Show(language.Text[15], language.Text[16], MessageBoxButtons.OKCancel) ==
            //    DialogResult.OK)
            //{
            //    IsExit = true;
            //    Close();
            //}
        }

        private void ItemInfoClick(object sender, EventArgs e)
        {
            InfoForm info = new InfoForm(Program.OptionsFile);
            info.Show(this);
        }

        private void ItemLanguageClick(object sender, EventArgs e)
        {
            if (language.Text == Languages.German)
            {
                IOFile.WriteLine(Program.OptionsFile, 6, "Language;English", true);
                language.Text = Languages.English;
                SetStrings();
            }
            else //if (mLanguage.Text == Languages.English)
            {
                IOFile.WriteLine(Program.OptionsFile, 6, "Language;German", true);
                language.Text = Languages.German;
                SetStrings();
            }
        }

        private void ItemNotifyIconClick(object sender, EventArgs e)
        {
            mNotifyIcon.Visible = !mNotifyIcon.Visible;
            String text = "NotifyIcon;" + Convert.ToByte(mNotifyIcon.Visible);
            IOFile.WriteLine(Program.OptionsFile, 5, text, true);
        }

        private void ItemSaveImageClick(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            //tDialog.InitialDirectory = "c:\\";
            dialog.Filter = @"PNG (*.png)|*.png|JPEG Files(*.jpg;*.jpeg)|" + 
                            @"*.jpg;*.jpeg|BMP (*.bmp)|*.bmp";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                switch (dialog.FilterIndex)
                {
                    case 1:
                        finalImage.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Png);
                        break;
                    case 2:
                        JpegEncoder.SaveJpeg(dialog.FileName, finalImage, 100);//100% quality
                        break;
                    case 3:
                        finalImage.Save(dialog.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
                        break;
                }
            }


        }

        private void ItemUseFastCutClick(object sender, EventArgs e)
        {
            //Reset ratio constraints
            mComboBox_ratio.SelectedIndex = 0;
            if (Current.Name == "")
            {
                MessageBox.Show(language.Text[51], language.Text[50]);
                return;
            }

            LoadFastcut(Current.Name);
        }

        private void LoadFastcutItemsClick(object sender, EventArgs e)
        {
            ToolStripMenuItem item = sender as ToolStripMenuItem;
            if (item != null)
            {
                LoadFastcut(item.Text);
            }
        }

        private void RemoveFastcutItemsClick(object sender, EventArgs e)
        {
            if (MessageBox.Show(
                            language.Text[40], 
                            language.Text[41], 
                            MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }

            ToolStripMenuItem item = sender as ToolStripMenuItem;
            if (item != null)
            {
                // string name = item.Text;
                fastcuts.Remove(item.Text);
                Program.SaveXml(fastcuts);
                UpdateFastcutToolStripMenuItems();
            }
        }

        private void SaveFastcutToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (StringDialog.Show(
                    ref tmpFastcutName,
                    language.Text[44],
                    language.Text[45],
                    tmpFastcutName, // Current.Name,
                    "OK",
                    language.Text[46]) == DialogResult.Cancel)
            {
                return;
            }

            if (fastcuts.Exists(tmpFastcutName))
            {
                if (MessageBox.Show(
                        language.Text[48],
                        language.Text[47],
                        MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    SaveFastcutToolStripMenuItem.PerformClick();
                    return;
                }
                fastcuts.Remove(tmpFastcutName);
                // resetting name, because after removing Current.Name = ""
                Current.Name = tmpFastcutName;
            }
            else
            {
                Current.Name = tmpFastcutName;
            }

            fastcuts.AddAsFirst(Current.Clone() as Fastcut);
            Program.SaveXml(fastcuts);
            UpdateFastcutToolStripMenuItems();
        }

        private void UpdateItemClick(object sender, EventArgs e)
        {
            if (isUpdateable)
            {
                if (MessageBox.Show(language.Text[39],
                                    language.Text[38],
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    IsExit = true;
                    VistaSecurity.RestartElevatedForUpdate();
                }
            }
            else
            {
                if (MessageBox.Show(
                    @"New version available. Do you want to download it from Screenshotz website (recommended)?",
                    @"New version available :-)",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("http://code.google.com/p/screenshotz/");
                }
            }
        }
    }
}
